package com.stylefeng.guns.modular.flagglory.warpper;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.stylefeng.guns.common.persistence.dao.QuestionCategoryMapper;
import com.stylefeng.guns.common.persistence.model.QuestionCategory;
import com.stylefeng.guns.core.base.warpper.BaseControllerWarpper;
import com.stylefeng.guns.core.util.SpringContextHolder;
import org.apache.commons.lang.StringUtils;

import java.util.Map;

/**
 * 部门列表的包装
 *
 * @author fengshuonan
 * @date 2017年4月25日 18:10:31
 */
public class QuestionWarpper extends BaseControllerWarpper {
    private QuestionCategoryMapper questionCategoryMapper = SpringContextHolder.getBean(QuestionCategoryMapper.class);

    public QuestionWarpper(Object list) {
        super(list);
    }


    @Override
    public void warpTheMap(Map<String, Object> map) {
        Integer categoryid = (Integer) map.get("categoryid");
        QuestionCategory pQuestionCategory = questionCategoryMapper.selectById(categoryid);
        if (null != pQuestionCategory) {
            map.put("category", pQuestionCategory.getName());
        } else {
            map.put("category", "无");
        }
        String info = map.get("info").toString();
        JSONObject infoJson = JSON.parseObject(info);
        map.put("infoText", infoJson.getString("infoText"));
        String answer = "";
        JSONArray answers = infoJson.getJSONArray("answers");
       for(int i = 0 ; i < answers.size(); i ++){
           int answerNum = i + 1;
           answer += "选项" + answerNum + ":" + answers.getString(i) + "<br>";
       }
        map.put("answer", answer);
        map.put("rightAnswer", "选项" + infoJson.getInteger("rightAnswer"));
    }

}
